#include <stdlib.h>
#include <ncurses.h>
#include <string.h>

typedef struct{
	int	x;
	int y;
}carcoords;


int car()
{	

	

	int 	c, Q, 
		row, 
		col,
		strow, 
		stcol;
		
	carcoords maincar;

	initscr();			/* Start curses mode 		  */
	cbreak();			/* Line buffering disabled	  */
	keypad(stdscr, TRUE);		/* Allows F1, arrows keys, etc.   */
	noecho();
	curs_set(0);


	wborder(stdscr, '|', '|', '-', '-', '+', '+', '+', '+');
	getmaxyx(stdscr,row,col);
	strow = row - 3;
	stcol = col/2;
	
	maincar.x = strow;
	maincar.y = stcol;
	

	mvprintw(maincar.x-1, maincar.y, "(|  |)");
	mvprintw(maincar.x, maincar.y, " |  |");
	mvprintw(maincar.x+1, maincar.y, "(|  |)");

	while((c = getch()) != 'q')
	{	switch(c)
		{	case 'a':
				move_car(&maincar, c);
				break;
			case 'd':
 	            move_car(&maincar, c);
				break;
			case 'w':
                move_car(&maincar, c);
				break;
			case 's':
                move_car(&maincar, c);
				break;	
		}
		

	}
		
	refresh();
	endwin();			/* End curses mode		  */

	return 0;
}

int move_car(carcoords *MC, int c){

	int row, col;	
	getmaxyx(stdscr,row,col);
	
	switch(c)
		{	case 'a':
				mvprintw(MC->x-1, MC->y, "      ");
				mvprintw(MC->x, MC->y, "      ");
				mvprintw(MC->x+1, MC->y, "      ");
				if(MC->y >= 10) MC->y-=10;
				draw_car(MC);
				break;
			case 'd':
				mvprintw(MC->x-1, MC->y, "      ");
				mvprintw(MC->x, MC->y, "      ");
				mvprintw(MC->x+1, MC->y, "      ");
 	            		if(MC->y <= (col - 15)) MC->y+=10;
 	            		draw_car(MC);
				break;
/*			case 'w':
				mvprintw(MC->x-1, MC->y, "      ");
				mvprintw(MC->x, MC->y, "      ");
				mvprintw(MC->x+1, MC->y, "      ");
                MC->x--;
                draw_car(MC);
				break;
			case 's':
				mvprintw(MC->x-1, MC->y, "      ");
				mvprintw(MC->x, MC->y, "      ");
				mvprintw(MC->x+1, MC->y, "      ");
                MC->x++;
                draw_car(MC);
				break;	
*/
		}
		
		return 0;	
}

int draw_car(carcoords *MC){

	
	mvprintw(MC->x-1, MC->y, "(|  |)");
	mvprintw(MC->x, MC->y, " |  |");
	mvprintw(MC->x+1, MC->y, "(|  |)");
	refresh();
	return 0;
	
}

